<?php

namespace App\Models\Custom;

use App\Models\Balance\Balance;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;

class Config extends Model
{
    protected $table = 'config';
    public $timestamps = false;
    protected $primaryKey = 'id';
    protected $guarded = ['_token'];



    public static function getConfig($cpid, $config_key)
    {
        return self::where(['cpid' => $cpid, 'config_key' => $config_key])->value('config_val');
    }

    public static function setConfig($cpid, $config_key, $config_val)
    {
        $info = self::where(['cpid' => $cpid, 'config_key' => $config_key])->first();
        if (!$info) {
            self::create(['cpid' => $cpid, 'config_key' => $config_key, 'config_val' => $config_val]);
        } else {
            self::where(['cpid' => $cpid, 'config_key' => $config_key])->update(['config_val' => $config_val]);
        }
    }
}
